/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						     campaign_file_ref.h

	$Header: /game/campaign_file_ref.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( CAMPAIGN_FILE_REF_H_INCLUDED )
#define CAMPAIGN_FILE_REF_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <assert.h>
#include <iosfwd>
#include <string>

#include "counted_ptr.h"
#include "standard_campaign_id.h"

// --------------------------------------------------------------------------
// t_campaign_file_ref_accessor - used to retrieve the data from a
// t_campaign_file_ref defined below
// --------------------------------------------------------------------------

class t_campaign_file_ref_accessor
{
public:
	// Member functions
	virtual void	access( std::string const & file_name );
	virtual void	access( t_standard_campaign_id campaign_id );

protected:
	// Destructor
	~t_campaign_file_ref_accessor() {}
};

// --------------------------------------------------------------------------
// t_campaign_file_ref_body - base class used for holding data in
// a t_campaign_file_ref defined below
// --------------------------------------------------------------------------

class t_campaign_file_ref_body : public t_counted_object
{
public:
	// Types
	typedef t_campaign_file_ref_accessor t_accessor;

	// Member functions
	virtual void	accept( t_accessor & accessor ) const = 0;
};

// --------------------------------------------------------------------------
// t_campaign_file_ref class - can be used to refer to a standard campaign
// or a custom campaign
// --------------------------------------------------------------------------

class t_campaign_file_ref
{
public:
	// Types
	typedef t_campaign_file_ref_accessor t_accessor;

	// Constructors
	t_campaign_file_ref();
	t_campaign_file_ref( std::string const & file_name );
	t_campaign_file_ref( t_standard_campaign_id campaign_id );

	// Member functions
	void	accept( t_accessor & accessor ) const;
	bool	is_set() const;
	bool	read( std::streambuf & stream );
	bool	write( std::streambuf & stream ) const;

private:
	// Types
	typedef t_campaign_file_ref_body	t_body;

	// Data members
	t_counted_ptr< t_body >	m_body_ptr;
};

// --------------------------------------------------------------------------
// t_campaign_file_ref inline members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline t_campaign_file_ref::t_campaign_file_ref()
{
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline void t_campaign_file_ref::accept( t_accessor & accessor ) const
{
	assert( m_body_ptr.get() != 0 );
	m_body_ptr->accept( accessor );
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline bool t_campaign_file_ref::is_set() const
{
	return m_body_ptr.get() != 0;
}

#endif // !defined( CAMPAIGN_FILE_REF_H_INCLUDED )
